package com.eleMall.controller;



import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.eleMall.entity.Result;
import com.eleMall.entity.ShoppingCart;
import com.eleMall.entity.User;
import com.eleMall.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author ximen
 * @since 2024-03-10
 */
@RestController
@RequestMapping("/eleMall/user")
@Api(tags = "用户(User)表控制层")
public class UserController {
    /**
     * 服务对象
     */
    @Autowired
    private UserService userService;

    /**
     * 分页查询
     *
     * @param pageSize 页面大小
     * @param page 页码
     * @return 查询结果
     */
    @ApiOperation("分页查询")
    @GetMapping("/page")
    public Result page(@ApiParam(value = "user 筛选条件") int page,int pageSize) {
        //分页构造器
        Page<User> pageInfo = new Page<>(page,pageSize);
        //条件构造器
        LambdaQueryWrapper<User> queryWrapper = new LambdaQueryWrapper<>();
        //添加排序条件，根据id进行排序
        queryWrapper.orderByAsc(User::getUserId);

        //分页查询
        userService.page(pageInfo,queryWrapper);
        return Result.success(pageInfo);
    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @ApiOperation("通过主键查询单条数据")
    @GetMapping("{id}")
    public Result queryById(@ApiParam(value = "id 主键") @PathVariable("id") Long id) {
        userService.getById(id);
        return Result.success();
    }


}
